package com.hezhiqin.lock.pool;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

/**
 * @program: homeWork
 * @description:
 * @author: hezhiqin
 * @create: 2020-02-10 15:21
 */
public class Test implements Runnable {
    @Override
    public void run() {
        try {
            Thread.sleep(10);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println(Thread.currentThread().getName());
    }

    static ExecutorService service = Executors.newFixedThreadPool(3);

    static ExecutorService service2 = Executors.newCachedThreadPool();

//    public static void main(String[] args) {
//        for (int i = 0; i < 100; i++) {
//            service.execute(new Test());
//        }
//        service.shutdown();
//    }

    public static void main(String[] args) {
        for (int i = 0; i < 10; i++) {
            final int index = i;
            try {
                Thread.sleep(index * 1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            service2.execute(()->{
                System.out.println(index);
            });

        }
    }

//    public static void main(String[] args) {
//        ScheduledExecutorService scheduledThreadPool = Executors.newScheduledThreadPool(5);
//        scheduledThreadPool.schedule(new Runnable() {
//            public void run() {
//                System.out.println("delay 3 seconds");
//            }
//        }, 3, TimeUnit.SECONDS);
//    }
}
